home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / ExceptionHandler-C-src / GetZoneInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-10  |  2.7 KB  |  98 lines  |  [TEXT/KAHL]

  1. /************************************************************************
  2.  
  3.     Initialize segment for Application.
  4.     
  5.     Created from Apple's Sample Code GetZoneList.c    January 31, 1989
  6.     
  7.     Modified Sept. 10th, 1990
  8.     Change MPPOpen() and ATPOpen() call to OpenDriver('.MPP',&refNum)
  9.     calls, as outlined in TechNote 224: Opening AppleTalk.
  10. ************************************************************************/
  11.  
  12. #include "MyExceptionHandler.h"
  13. #include "GetZoneInclude.h"
  14.  
  15. /* Globs */
  16. extern SysEnvRec    gMac;                    /* set up by Initialize */
  17. extern Boolean        gHasWaitNextEvent;        /* set up by Initialize */
  18. extern Boolean        gInBackground;            /* maintained by Initialize and DoEvent */
  19.     
  20. extern ListHandle    gList;                    /* the list to be filled with zone names */
  21.  
  22. /*     globals added for C sample use as the Pascal 
  23.     example used those horrid :-) nested procedures! */
  24. extern ATPPBPtr    gATPPBPtr;    /* the parameter block for GetZoneList call */
  25. extern Ptr            gZones;     /* the data buffer for GetZoneList call */
  26. extern DialogPtr    gErrDlg;    /* Dialog used for displaying zone list */ 
  27.  
  28. #define _Unimplemented 0x9f
  29. Boolean TrapAvailable(tNumber, tType)
  30. short        tNumber;
  31. int            tType;
  32. {
  33.     return( NGetTrapAddress(tNumber, tType) != GetTrapAddress(_Unimplemented) );
  34. }  /* TrapAvailable */
  35.  
  36.  
  37. pascal void HandleErr_Initialize(error, message)
  38.     short    error;
  39.     long    message;
  40. {
  41.         if (error > 0) AlertUser(0, error);
  42.         else AlertUser(error, message);
  43.         ExitToShell();    
  44. } /* HandleErr_Initialize */
  45.  
  46. void Initialize()
  47. {
  48.     Handle            menuBar;
  49.     OSErr            ignoreError;
  50.     long            total, contig;
  51.     Boolean            ignoreResult;
  52.     EventRecord        event;
  53.     short            count, refNum;
  54.     FailInfo        fi;
  55.  
  56.     gHasWaitNextEvent = TrapAvailable(_WaitNextEvent, ToolTrap);
  57.     gInBackground = false;
  58.  
  59.     InitGraf(&thePort);
  60.     InitFonts();
  61.     InitWindows();
  62.     InitMenus();
  63.     TEInit();
  64.     InitDialogs(nil);
  65.     InitCursor();
  66.  
  67.     /* get MultiFinder started */
  68.     for (count=1;count<3;count++)
  69.         ignoreResult = EventAvail(everyEvent, &event);
  70.     
  71.     CatchCFailures(&fi, HandleErr_Initialize);
  72.  
  73. #if 0
  74.     /*  FailOSErrMsg(MPPOpen(), eAppleTalk);    
  75.         FailOSErrMsg(ATPLoad(), eAppleTalk);    /*Change to OpenDriver call */
  76. #endif
  77.     FailOSErrMsg(OpenDriver("\p.MPP", &refNum),eAppleTalk);    /* See: Tn.224 */
  78.                 
  79.     ignoreError = SysEnvirons(kSysEnvironsVersion, &gMac);
  80.     if (gMac.machineType < 0)    Failure(0, eWrongMachine);
  81.     
  82.     if ((char *) GetApplLimit() - (char *) ApplicZone() < kMinHeap)
  83.         Failure(0, eSmallSize);
  84.  
  85.     PurgeSpace(&total, &contig);
  86.     if (total < kMinSpace)    Failure(0, eNoMemory);
  87.  
  88.     menuBar = GetNewMBar(rMenuBar);                /*    read menus into menu bar */
  89.     FailnilMsg(menuBar, eNoMemory);
  90.     
  91.     SetMenuBar(menuBar);                        /*    install menus */
  92.     DisposHandle(menuBar);
  93.     AddResMenu(GetMHandle(mApple), 'DRVR');        /*    add DA names to Apple menu */
  94.     DrawMenuBar();
  95.     
  96.     Success(&fi);
  97. } /* Initialize */
  98.